import 'dart:async';
import 'package:dio/dio.dart';

class Api {
  static Dio dio = Dio(BaseOptions(
    baseUrl: 'http://192.168.85.101:8080/catering-api',
    connectTimeout: 10000,
    receiveTimeout: 30000,
    responseType: ResponseType.json
  ));



  Future capturePaymentIntent(paymentIntentId) async {
    Response response = await dio.post('/order/capturePaymentIntent',
        queryParameters: {'paymentIntentId': paymentIntentId},
    );
    var data = response.data;
    return data;
  }


  ///创建意向订单
  Future posCreatePaymentIntent(totalPaid) async {
    Response response = await dio.post('/order/createPaymentIntent',
        //cardReaderID:设备id,stripe后台生成||totalPaid:支付金额||subAmount:分给子账号的金额||subAccountId子账号id
        queryParameters: {
          'totalPaid': totalPaid,
        });
    var _data = response.data;
    if (_data != null && _data['code'] == 200) {
      return _data['result'];
    }
    return "";
  }
  Future tippingIsAddedToTheTransaction(totalPaid,paymentIntentId) async {
    Response response = await dio.post('/order/tippingIsAddedToTheTransaction',
        //cardReaderID:设备id,stripe后台生成||totalPaid:支付金额||subAmount:分给子账号的金额||subAccountId子账号id
        queryParameters: {
          'totalPaid': totalPaid,
          'paymentIntentId': paymentIntentId,
        });
    var _data = response.data;
    if (_data != null && _data['code'] == 200) {
      return _data['result'];
    }
    return "";
  }


  Future<String> getConnectionToken() async {
    Response response = await dio.post('/sys/connectionToken');
    var _data = response.data;
    if (_data != null && _data['code'] == 200) {
      return _data['result'];
    }
    return "";
  }

}
